import random
from PIL import ImageColor, Image
import numpy
import cv2

values = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15']
value_dict = [['A','10'],['B','11'],['C','12'],['D','13'],['E','14'],['F','15']]
start = "#"

def contrastcolour(colour):
    if colour[0] == '#':
        colour = colour[1:]
    rgb = (colour[0:2], colour[2:4], colour[4:6])
    comp = ['%02X' % (255 - int(a, 16)) for a in rgb]
    return ''.join(comp)

def startcolour():
    colour = "#"
    for i in range(6):
        x = values[random.randint(0,len(values)-1)]

        for thing in value_dict:
            if x == thing[1]:
                x = thing[0]
        colour = colour + x
    return colour

base = startcolour()
contrast = start + contrastcolour(base)
def hex_to_rgb(value):
    value = value.lstrip('#')
    lv = len(value)
    return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
print(f"The colours: {[base, contrast]}, hex: {[hex_to_rgb(base), hex_to_rgb(contrast)]}")
print(f"{[ImageColor.getrgb(base), ImageColor.getrgb(contrast)]}")

np = numpy.zeros((500, 500, 3), dtype=numpy.uint8)
np[:] = ImageColor.getrgb(base)

np = cv2.putText(np,'texting with someone...', (80, 250), 2, 1, ImageColor.getrgb(contrast),2, cv2.LINE_AA)
cv2.imshow('base', np)

cv2.waitKey(0)
# bg, textcolor
[(149, 68, 1), (106, 187, 254)]
[(246, 213, 90), (9, 42, 165)]
[(129, 8, 165), (126, 247, 90)]
[(105, 7, 50), (150, 248, 205)]
[(226, 43, 36), (29, 212, 219)]
[(191, 174, 241), (64, 81, 14)]
[(94, 4, 245), (161, 251, 10)]
[(20, 223, 238), (235, 32, 17)]
[(188, 108, 255), (67, 147, 0)]
[(251, 211, 127), (4, 44, 128)]
[(110, 233, 181), (145, 22, 74)]
[(29, 241, 17), (226, 14, 238)]
[(25, 246, 126), (230, 9, 129)]
[(82, 240, 137), (173, 15, 118)]
[(52, 6, 109), (203, 249, 146)]
[(254, 189, 31), (1, 66, 224)]
[(22, 239, 132), (233, 16, 123)]
[(179, 237, 198), (76, 18, 57)]
[(186, 188, 84), (69, 67, 171)]
[(43, 246, 201), (212, 9, 54)]
[(83, 59, 137), (172, 196, 118)]
[(160, 18, 251), (95, 237, 4)]
[(94, 152, 205), (161, 103, 50)]
[(71, 13, 20), (184, 242, 235)]
[(145, 160, 225), (110, 95, 30)]
[(202, 241, 197), (53, 14, 58)]
[(153, 212, 70), (102, 43, 185)]
[(215, 212, 76), (40, 43, 179)]
[(4, 166, 3), (251, 89, 252)]
[(5, 228, 122), (250, 27, 133)]
[(15, 118, 8), (240, 137, 247)]
[(182, 181, 28), (73, 74, 227)]
[(232, 242, 249), (23, 13, 6)]
[(91, 79, 9), (164, 176, 246)]
[(186, 174, 223), (69, 81, 32)]
[(152, 220, 193), (103, 35, 62)]
[(77, 235, 251), (178, 20, 4)]
[(224, 162, 255), (31, 93, 0)]
[(4, 246, 179), (251, 9, 76)]
[(4, 111, 186), (251, 144, 69)]
[(220, 251, 181), (35, 4, 74)]
[(168, 209, 115), (87, 46, 140)]
[(174, 31, 65), (81, 224, 190)]
[(21, 74, 47), (234, 181, 208)]
[(217, 254, 107), (38, 1, 148)]
[(109, 210, 225), (146, 45, 30)]
[(12, 29, 0), (243, 226, 255)]
[(241, 158, 149), (14, 97, 106)]
[(143, 31, 219), (112, 224, 36)]
[(36, 41, 35), (219, 214, 220)]
[(220, 218, 88), (35, 37, 167)]
[(49, 40, 204), (206, 215, 51)]
[(96, 14, 228), (159, 241, 27)]
[(221, 10, 69), (34, 245, 186)]
[(240, 186, 152), (15, 69, 103)]
[(177, 21, 42), (78, 234, 213)]
[(150, 217, 142), (105, 38, 113)]
[(43, 20, 5), (212, 235, 250)]
[(62, 251, 143), (193, 4, 112)]
[(178, 18, 225), (77, 237, 30)]
[(200, 50, 40), (55, 205, 215)]
[(226, 247, 77), (29, 8, 178)]
[(192, 168, 160), (63, 87, 95)]
[(2, 239, 145), (253, 16, 110)]
[(44, 224, 86), (211, 31, 169)]
[(14, 24, 64), (241, 231, 191)]
[(28, 198, 187), (227, 57, 68)]
[(73, 45, 71), (182, 210, 184)]
[(226, 202, 96), (29, 53, 159)]
[(5, 205, 132), (250, 50, 123)]
[(254, 231, 152), (1, 24, 103)]
[(139, 46, 213), (116, 209, 42)]
[(144, 254, 140), (111, 1, 115)]
[(160, 197, 132), (95, 58, 123)]
[(116, 173, 0), (139, 82, 255)]
[(49, 55, 157), (206, 200, 98)]
[(136, 177, 251), (119, 78, 4)]
[(217, 242, 164), (38, 13, 91)]
[(134, 103, 2), (121, 152, 253)]
[(248, 164, 119), (7, 91, 136)]
[(18, 67, 66), (237, 188, 189)]
[(117, 58, 76), (138, 197, 179)]
[(158, 35, 66), (97, 220, 189)]
[(18, 25, 12), (237, 230, 243)]
[(143, 28, 166), (112, 227, 89)]
[(143, 248, 7), (112, 7, 248)]
[(122, 36, 95), (133, 219, 160)]
[(61, 214, 185), (194, 41, 70)]
[(120, 125, 29), (135, 130, 226)]
[(130, 249, 90), (125, 6, 165)]
[(51, 13, 94), (204, 242, 161)]
[(223, 172, 6), (32, 83, 249)]
[(7, 98, 127), (248, 157, 128)]
[(118, 106, 48), (137, 149, 207)]
[(44, 249, 127), (211, 6, 128)]
[(158, 248, 89), (97, 7, 166)]
[(20, 244, 125), (235, 11, 130)]
[(245, 250, 235), (10, 5, 20)]
[(87, 23, 215), (168, 232, 40)]
[(66, 160, 245), (189, 95, 10)]
[(0, 109, 72), (255, 146, 183)]
[(26, 206, 94), (229, 49, 161)]
[(43, 123, 13), (212, 132, 242)]
[(180, 240, 71), (75, 15, 184)]
[(126, 40, 9), (129, 215, 246)]
[(173, 204, 141), (82, 51, 114)]